import {deleteAction, getAction, postAction, downFile, getFileAccessHttpUrl} from '@/api/request'

export const report = {

    data() {
        return {
            url: {
                list: "/api/ac/subsistence/reportStatisticalServiceImpl/statisticalReport",
                exportExcel: "/api/ac/subsistence/reportStatisticalServiceImpl/ExportReport",
                getInfo: "/api/ac/subsistence/reportStatisticalServiceImpl/getInfo",
                confirmSubmit: "/api/ac/subsistence/reportStatisticalServiceImpl/createConfirmSubmit",
            },
            result: [],
            Loading: false,
            isConfirm: false
        }
    },

    methods: {
        search() {
            if (this.queryParam.monthTime) {
                this.queryParam.time = this.DateFormat(this.queryParam.monthTime, 'YYYY-MM-DD');
                this.statisticalReport();
            } else {
                this.$Message.error("请选择统计年月");
            }
        },
        exportE() {
            if (this.queryParam.monthTime) {
                this.queryParam.time = this.DateFormat(this.queryParam.monthTime, 'YYYY-MM-DD');
                this.exportExcel();
            } else {
                this.$Message.error("请选择统计年月");
            }
        },
        statisticalReport() {
            if (this.queryParam.monthTime) {
                this.Loading = true;
                postAction(this.url.list, this.queryParam).then((res) => {
                    if (res.data.errcode != 0) {
                        this.$Message.error(res.data.errmsg);
                    } else {
                        this.result = res.data.data;
                        this.getInfo();
                    }
                }).finally(() => {
                    this.Loading = false;
                })
            }
        },
        confirm() {
            if (this.queryParam.monthTime) {
                this.queryParam.time = this.DateFormat(this.queryParam.monthTime, 'YYYY-MM-DD');
                this.$Modal.confirm({
                    title: '确定统计数据无误？',
                    onOk: () => {
                        var that = this;
                        this.Loading = true;
                        postAction(that.url.confirmSubmit, this.queryParam).then((res) => {
                            if (res.data.errcode == 0) {
                                that.$Message.success("确认成功！");
                                that.isConfirm = false;
                            } else {
                                that.$Message.error(res.data.errmsg);
                            }
                        }).finally(() => {
                            this.Loading = false;
                        });
                    }
                })
            } else {
                this.$Message.error("请选择统计年月");
            }
        },

        getInfo() {
            var that = this;
            this.Loading = true;
            if (this.queryParam.monthTime) {
                this.queryParam.time = this.DateFormat(this.queryParam.monthTime, 'YYYY-MM') + "-01"
            }
            postAction(that.url.getInfo, this.queryParam).then((res) => {
                if (res.data.errcode == 0) {
                    if (res.data.data) {
                        that.isConfirm = true;
                    } else {
                        that.isConfirm = false;
                    }
                } else {
                    that.$Message.error(res.data.errmsg);
                }
            }).finally(() => {
                this.Loading = false;
            });
        },

        changeMonth() {
            this.result = [];
            this.isConfirm = false;
        }
    }

}